<template>
  <el-dialog title="选择班级" :visible.sync="visible" :close-on-click-modal='false' fullscreen center append-to-body>
    <el-button class="miui-dialog-close-btn" @click="visible = false">关闭页面</el-button>
    <el-form label-width="80px" inline>
      <el-form-item label="学校名称">
        <el-input v-model="dataForm.schoolName" readonl></el-input>
      </el-form-item>
      <el-form-item label="年级名称">
        <el-input v-model="dataForm.gradeName" readonl></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="searchHandle">查询</el-button>
        <el-button type="info" @click="clearHandle">清空</el-button>
      </el-form-item>
    </el-form>
    <div class="avue-crud__pagination" style="margin-bottom: 25px;">
      <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100, 200]" :page-size="pageSize" :total="totalPage" background layout="total, sizes, prev, pager, next">
      </el-pagination>
    </div>

    <el-table :data="dataList" height="calc(100vh - 215px)" ref="singleTable" border v-loading="dataListLoading">
      <el-table-column type="index" width="50">
        <template slot-scope="scope">
          <el-radio v-model="dataForm.classId" :label="scope.row.id" style="position: relative;left: 6px;top:-2px;" @change="checkClass(scope.row)">&nbsp;</el-radio>
        </template>
      </el-table-column>
      <el-table-column prop="className" label="班级名称"></el-table-column>
      <el-table-column prop="gradeName" label="年级名称"></el-table-column>
      <el-table-column prop="schoolName" label="学校名称"></el-table-column>
    </el-table>
  </el-dialog>
</template>

<script>
  import { filterParams } from '@/util/tools'
  import { fetchList } from '@/api/pvm/class'
  export default {
    data(){
      return {
        visible: false,
        dataForm: {},
        dataList: [],
        dataListLoading: false,
        pageIndex: 1,
        pageSize: 100,
        totalPage: 0,
      }
    },
    methods: {
      init(data){
        this.visible = true
        if(data){
          this.dataForm = JSON.parse(data)
        }
        this.dataList = []
      },
      searchHandle(){
        this.pageIndex = 1
        this.getDataList()
      },
      clearHandle(){
        for(let key in this.dataForm){
          this.dataForm = ''
        }
      },
      getDataList(){
        this.dataListLoading = true
        let params1 = {current: this.pageIndex,size: this.pageSize}
        let params2 = filterParams(this.dataForm)
        fetchList(Object.assign(params1,params2)).then(response => {
          if(response.data.code == '0'){
            this.dataList = response.data.data.records
            this.totalPage = response.data.data.total
          }else{
            this.$message.error(response.data.msg)
          }
          this.dataListLoading = false
        })
      },
      sizeChangeHandle(val){
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      currentChangeHandle(val){
        this.pageIndex = val
        this.getDataList()
      },
      checkClass(data){
        this.$emit('refreshForm',data)
        this.visible = false
      }
    }
  }
</script>

<style>
</style>
